package task1;

import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 东莞呵呵
 * Date:2022-09-20
 * Time:21:05
 */
public class TestDemo2 {
    public static long sum1 = 0;
    public static long sum2 = 0;

    public static void main(String[] args) throws InterruptedException {
        int[] arr = new int[1000_0000];
        for (int i = 0; i < 1000_0000; i++) {
            arr[i] = (int) (Math.random() * 100) + 1;
        }

        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < arr.length; i += 2) {
                    sum1 += arr[i];
                }
            }
        });
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 1; i < arr.length; i += 2) {
                    sum2 += arr[i];
                }
            }
        });
        long time1 = System.currentTimeMillis();
        t1.start();
        t1.join();
        long time2 = System.currentTimeMillis();
        System.out.println(time2-time1);
        long time3 = System.currentTimeMillis();
        t2.start();
        t2.join();
        long time4 = System.currentTimeMillis();
        System.out.println(time4-time3);
        System.out.println(sum1+sum2);
    }
}
